From: Keir Fraser Date: Thu, 11 Dec 2008 11:36:00 +0000 (+0000) Subject: x86: unify local_irq_XXX() X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~14026^2~37 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=3bc61439add8aa6386afcff33a46a85d2247b960;p=xen.git x86: unify local_irq_XXX() This also removes an inconsistency in that x86-64's __save_flags() had a memory clobber, while x86_32's didn't. It further adds type checking since blindly using {pop,push}{l,q} on a memory operand of unknown size bares the risk of corrupting other data. Finally, it eliminates the redundant (with local_irq_restore()) __restore_flags() macro and renames __save_flags() to local_save_flags(), making the naming consistent with Linux (again?). Signed-off-by: Jan Beulich --- diff --git a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h index c257513dad..ced68d0633 100644 --- a/xen/include/asm-x86/system.h +++ b/xen/include/asm-x86/system.h @@ -1,8 +1,7 @@ #ifndef __ASM_SYSTEM_H #define __ASM_SYSTEM_H -#include -#include +#include #include #define read_segment_register(name) \ @@ -171,10 +170,27 @@ static always_inline unsigned long __cmpxchg( /* used when interrupts are already enabled or to shutdown the processor */ #define halt() asm volatile ( "hlt" : : : "memory" ) +#define local_save_flags(x) \ +({ \ + BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ + asm volatile ( "pushf" __OS " ; pop" __OS " %0" : "=g" (x)); \ +}) +#define local_irq_save(x) \ +({ \ + local_save_flags(x); \ + local_irq_disable(); \ +}) +#define local_irq_restore(x) \ +({ \ + BUILD_BUG_ON(sizeof(x) != sizeof(long)); \ + asm volatile ( "push" __OS " %0 ; popf" __OS \ + : : "g" (x) : "memory", "cc" ); \ +}) + static inline int local_irq_is_enabled(void) { unsigned long flags; - __save_flags(flags); + local_save_flags(flags); return !!(flags & (1<<9)); /* EFLAGS_IF */ } diff --git a/xen/include/asm-x86/x86_32/system.h b/xen/include/asm-x86/x86_32/system.h index 5707af8e86..56ef751ec7 100644 --- a/xen/include/asm-x86/x86_32/system.h +++ b/xen/include/asm-x86/x86_32/system.h @@ -101,14 +101,4 @@ static inline void atomic_write64(uint64_t *p, uint64_t v) #define mb() \ asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" ) -#define __save_flags(x) \ - asm volatile ( "pushfl ; popl %0" : "=g" (x) : ) -#define __restore_flags(x) \ - asm volatile ( "pushl %0 ; popfl" : : "g" (x) : "memory", "cc" ) - -#define local_irq_save(x) \ - asm volatile ( "pushfl ; popl %0 ; cli" : "=g" (x) : : "memory" ) -#define local_irq_restore(x) \ - __restore_flags(x) - #endif /* __X86_32_SYSTEM_H__ */ diff --git a/xen/include/asm-x86/x86_64/system.h b/xen/include/asm-x86/x86_64/system.h index 229fc15292..fa9b3118b0 100644 --- a/xen/include/asm-x86/x86_64/system.h +++ b/xen/include/asm-x86/x86_64/system.h @@ -55,14 +55,4 @@ static inline void atomic_write64(uint64_t *p, uint64_t v) #define mb() \ asm volatile ( "mfence" : : : "memory" ) -#define __save_flags(x) \ - asm volatile ( "pushfq ; popq %q0" : "=g" (x) : :"memory" ) -#define __restore_flags(x) \ - asm volatile ( "pushq %0 ; popfq" : : "g" (x) : "memory", "cc" ) - -#define local_irq_save(x) \ - asm volatile ( "pushfq ; popq %0 ; cli" : "=g" (x) : : "memory" ) -#define local_irq_restore(x) \ - __restore_flags(x) - #endif /* __X86_64_SYSTEM_H__ */